<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>算法文件</title>
    <%-- 全站样式 --%>
    <jsp:include page="/WEB-INF/jsps/template_style.jsp"></jsp:include>
    
    <!--算法文件css-->
    <link rel="stylesheet" href="assets/css/folder/file.css">

    <!--Datatables所需要的js和css文件-->
    <script type="text/javascript" src="assets/css/dataTables.bootstrap.css"></script>
    <script type="text/javascript" src="assets/js/jquery.dataTables.min.js"></script>
    <script type="text/javascript" src="assets/js/dataTables.bootstrap.js"></script>

    <!--右击菜单js-->
    <script type="text/javascript" src="assets/js/BootstrapMenu.min.js"></script>

</head>

<body>
<div class="page-container">
 	<%--侧边栏 --%>
	<jsp:include page="/WEB-INF/jsps/sidebar.jsp"></jsp:include>

    <div class="main-content">
		<%--导航栏 --%>
		<jsp:include page="/WEB-INF/jsps/navbar.jsp"></jsp:include>
        <!--算法文件栏目-->
        <section class="gallery-env">
            <div class="row">
                <div class="col-sm-12 mailbox-right">
                    <div class="album-header">
                        <div class="row" style="margin-top: -5px;">
                            <div class="col-sm-12">
                                <h2>算法文件</h2>
                                <ul class="album-options list-unstyled list-inline" style="margin-top: -10px">
                                    <li>
                                        <button type="button" class="btn btn-default buttonself1 back1">
                                            <i class="fa-reply fontstyle"></i>返回上一级</button>
                                    </li>
                                    <li>
                                        <button type="button" class="btn btn-default buttonself1 download1">
                                            <i class="fa-download fontstyle"></i>下载</button>
                                    </li>
                                    <li>
                                        <button type="button" class="btn btn-default buttonself1 delete1">
                                            <i class="fa-trash fontstyle"></i>删除</button>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>

                    <!-- DataTables -->
                    <section class="mailbox-env" >
                        <div class="mail-env" >
                            <!--第二步：添加如下 HTML 代码-->
                            <div  width="95%" style="margin-left:20px;" >
                                <div class="album-header">
                            <table id="example" class="table table-striped table-bordered" style="width: 95%" cellspacing="0" >
                                <thead>
                                <tr>
                                    <th class="no-sorting">
                                        全选<input type="checkbox" class="a" name="checkbox" id="btn1">
                                    </th>
                                    <th>算法名称</th>
                                    <th>算法类别</th>
                                    <th>版本号</th>
                                    <th>上传时间</th>
                                </tr>
                                </thead>
                                <tbody id="datasAlgorithm1">
                                 <c:choose>
                                      <c:when test="${fileStatus.equals('0')}">
                                          
                                      </c:when>
                                      <c:otherwise>
                                          <c:forEach var="algorithmFile" items="${datasAlgorithm}">
                                           <tr class="favorite algorithmInto" data-favoriteID="${algorithmFile.id}" style="cursor:pointer">
                                               <td><input type="checkbox"  name="checkbox"></td>
                                               <td>${algorithmFile.algorithmID}</td>
			                                   <td>${algorithmFile.algorithmName}</td>
			                                   <td>${algorithmFile.algorithmVesion}</td>
			                                   <td>${algorithmFile.algorithmUploadtime}</td>
                                           </tr>
                                          </c:forEach>
                                      </c:otherwise>
                                  </c:choose>    
                                </tbody>
                            </table>
                            </div>
                            <script type="text/javascript">
                            	
                                <!--第三步初始化Datatables-->
                                $(document).ready(function() {
                                    $("#example").DataTable( {
                                        "language": {
                                            "url": "../assets/js/dataTable.zh_CN.json",
                                        },
                                        "bPaginage":true
                                    } );

                                    $("#btn1").on('click', function() {
                                        if ($(":checkbox").prop("checked")) {
                                            $(":checkbox").prop("checked",true);
                                        }
                                        else {
                                            $(":checkbox").prop("checked",false);
                                        }
                                        });

                                    <!--右击菜单开始-->
                                    /*文件操作*/
                                    var menufile1 = new BootstrapMenu('.algorithmInto', {//初始化插件
                                        //fetchElementData获取元数据
                                        fetchElementData:function($rowElem){
                                            var data = $rowElem;
                                            return data;    //return的目的是给下面的onClick传递参数
                                        },

                                        /*BootstrapMenu的构造函数第一个参数接收一个字符串格式的元素选择器，第二个参数是一个options参数对象。
                                         options对象必须至少有一个actions数组，数组中包含右键菜单的action。*/
                                        actions: [{
                                            name: '查看',
                                            onClick: function(obj) {  
                                             var algorithmID=obj.attr("data-favoriteID");
                                            	$.ajax({
                             	    		       url:"/getAlgorithmByID.do",
                             	    		       type:"POST",
                             	    		       dataType:"json",
                             	    		       data:{'algorithmID': algorithmID},
                             	    		       success: function(data){
                             	    		    	   $("#id1").val(data.datasAlgorithm[0].id);
                            	    		    	   $("#id1").hide();
                            	    		    	   $("#fileID").val(data.datasAlgorithm[0].fileID);
                            	    		    	   $("#fileID").hide();
                             	    		    	   $("#algorithmID").val(data.datasAlgorithm[0].algorithmID);
                             	    		    	   $("#algorithmName").val(data.datasAlgorithm[0].algorithmName);
                             	    		    	   $("#algorithmVesion").val(data.datasAlgorithm[0].algorithmVesion);
                             	    		    	   $("#algorithmUploadtime").val(data.datasAlgorithm[0].algorithmUploadtime);
                             	    		    	   $("#algorithmSort").val(data.datasAlgorithm[0].algorithmSort);
                             	    		    	   $("#algorithmLanguag").val(data.datasAlgorithm[0].algorithmLanguag);
                             	    		    	   $("#algorithmDscription").val(data.datasAlgorithm[0].algorithmDscription);
                             	    		    	   $('#look').modal('show')
                             	    		       },
                             	    		       error: function(XMLHttpRequest, textStatus, errorThrown) {
                             	    				   alert(XMLHttpRequest.status);
                             	    				   alert(XMLHttpRequest.readyState);
                             	    				   alert(textStatus);
                             	    				     },
                             	    			}); 
                                            }
                                        }, {
                                            name: '删除',
                                            onClick: function(obj) {
                                            	var algorithmID=obj.attr("data-favoriteID");
                                            	$.ajax({
                              	    		       url:"/deleteAlgorithm.do",
                              	    		       type:"POST",
                              	    		       dataType:"json",
                              	    		       data:{'algorithmID': algorithmID},
                              	    		       success: function(data){
                              	    		    	 obj.remove();
                              	    		       },
                              	    		       error: function(XMLHttpRequest, textStatus, errorThrown) {
                              	    				   alert(XMLHttpRequest.status);
                              	    				   alert(XMLHttpRequest.readyState);
                              	    				   alert(textStatus);
                              	    				     },
                              	    			}); 
                                            }
                                        },{
                                            name: '下载',
                                            onClick: function(obj) {
                                            	var algorithmID=obj.attr("data-favoriteID");
                                            	var hre = '/downAlgorithm.do?algorithmID='+algorithmID;
                                            	location.href = hre;
                                            }
                                        }]
                                    });
                                    <!--右击菜单结束-->
									
                                    /*修改算法*/
                                    $(document).on("click", "#updateAlgorithm", function(){
                                    	$.ajax({
                       	    		       url:"/updateAlgorithm.do",
                       	    		       type:"POST",
                       	    		       dataType:"json",
                       	    		       data:{'algorithmVesion': $("#algorithmVesion").val(),
                       	    		    	   	'algorithmUploadtime':$("#algorithmUploadtime").val(),
                       	    		    	   	'algorithmLanguag':$("#algorithmLanguag").val(),
                       	    		    	   	'algorithmSort':$("#algorithmSort").val(),
                       	    		    	   	'algorithmDscription':$("#algorithmDscription").val(),
                       	    		    	   	'algorithmName':$("#algorithmName").val(),
                       	    		    	   	'algorithmID':$("#algorithmID").val(),
                       	    		    	   	'fileID':$("#fileID").val(),
                       	    		    	   	'id1': $("#id1").val()
                       	    		    	   },
                       	    		       success: function(data){
                       	    		       		$('#look').modal('hide');
                       	    		       		console.log(data);
                       	    		       		$('#datasAlgorithm1').html("");
                       	    		       		$.each(data.datasAlgorithm,function(n,value){
                       	    		       		$('#datasAlgorithm1').append("<tr class='favorite algorithmInto' data-favoriteID='"
	                       	    		       			+value.id+"' style='cursor:pointer'>"
	                       	    		       			+"<td>"+value.algorithmID+"</td>"
	                       	    		       			+"<td>"+value.algorithmName+"</td>"
	                       	    		       			+"<td>"+value.algorithmSort+"</td>"
	                       	    		       			+"<td>"+value.algorithmVesion+"</td>"
	                       	    		       			+"<td>"+value.algorithmUploadtime+"</td>");	
                       	    		       		});
                       	    		       		
                       	    		       }
                                     	});                                   
                                    });
                                    
                                    /*删除文件*/
                                    $(document).on("click", ".delete1", function(){                                   	
                                        $('table :checkbox').each(function(){
                                            var isChecked = $(this).prop('checked');     // $(this) 获取当前的循环对象，此例中表示 table 中的 checkbox 子元素 集合中的一个元素
                                            if(isChecked) {                                  	
                                            	var algorithmID = $(this).parent().parent(".algorithmInto").attr("data-favoriteID");
                                            	if(algorithmID){
                                            		$(this).parent().parent(".algorithmInto").remove();
	                                            	$.ajax({
	                               	    		       url:"/deleteAlgorithm.do",
	                               	    		       type:"POST",
	                               	    		       dataType:"json",
	                               	    		       data:{'algorithmID': algorithmID},
	                               	    		       success: function(data){
	                               	    		    	 obj.remove();
	                               	    		       },
	                               	    		       error: function(XMLHttpRequest, textStatus, errorThrown) {
	                               	    				   alert(XMLHttpRequest.status);
	                               	    				   alert(XMLHttpRequest.readyState);
	                               	    				   alert(textStatus);
	                               	    				     },
	                               	    			}); 
                                            	}
                                                 
                                            }
                                        }) ;
                                    });
                                    
                                    /* 下载文件 */
                                    $(document).on("click",".download1",function(){
                                    	$('table :checkbox').each(function(){
                                            var isChecked = $(this).prop('checked');     // $(this) 获取当前的循环对象，此例中表示 table 中的 checkbox 子元素 集合中的一个元素
                                            if(isChecked) {                                  	
                                            	var algorithmID = $(this).parent().parent(".algorithmInto").attr("data-favoriteID");
                                            	if(algorithmID){
                                            		var hre = '/downAlgorithm.do?algorithmID='+algorithmID;
                                                	$(location).attr('href', hre);
                                                	alert("已经添加下载队列");
                                            	}
                                                 
                                            }
                                        }) ;
                                    })
                                    /*放回上一级*/
                                    $(document).on("click",".back1",function () {
                                        $(location).prop("href","/getAlgorithmDir.do");
                                    })
                                } );
                            </script>

                            </div>
                        </div>
                    </section>
                </div>

            </div>
        </section>
            	<%--页脚 --%>
		<jsp:include page="/WEB-INF/jsps/footer.jsp"></jsp:include>
    </div>
</div>


    <!-- 模态框（Modal） -->

    <!--查看算法开始-->
    <div class="modal fade" id="look" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">查看算法</h4>
                </div>
                <div class="modal-body">
                    <div class="panel panel-default">
                        <div class="panel-body">
                            <form action="" role="form" class="form-horizontal"  >
                               
                                <div class="form-group">
                                    <label class="col-sm-3 control-label" for="algorithmID">算法编号 <font color="red">*</font></label>
                                    <div class="col-sm-6">
                                        <input type="text" class="form-control" name="algorithmID" id="algorithmID"  maxlength="16" readonly="readonly" required>
                                    </div>
                                </div>
                                <div class="form-group-separator"></div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label" for="algorithmUploadtime">上传时间 <font color="red">*</font></label>
                                    <div class="col-sm-6">
                                        <input type="text" class="form-control" name="algorithmUploadtime" id="algorithmUploadtime" maxlength="16" readonly="readonly" required>
                                    </div>
                                </div>
                                <div class="form-group-separator"></div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label" for="algorithmName">算法名称 <font color="red">*</font></label>
                                    <div class="col-sm-6">
                                        <input type="text" class="form-control" name="algorithmName" id="algorithmName"  maxlength="16" required>
                                    </div>
                                </div>
                                <div class="form-group-separator"></div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label" for="algorithmVesion">算法版本号 <font color="red">*</font></label>
                                    <div class="col-sm-6">
                                        <input type="text" class="form-control" name="algorithmVesion" id="algorithmVesion" maxlength="16" required>
                                    </div>
                                </div>
                                <div class="form-group-separator"></div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label" for="algorithmSort">算法类型 <font color="red">*</font></label>
                                    <div class="col-sm-6">
                                        <input type="text" class="form-control" name="algorithmSort" id="algorithmSort" maxlength="16" required>
                                    </div>
                                </div>
                                <div class="form-group-separator"></div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label" for="algorithmLanguag">算法语言<font color="red">*</font></label>
                                    <div class="col-sm-6">
                                        <input type="text" class="form-control" name="algorithmLanguag" id="algorithmLanguag" maxlength="16" required>
                                    </div>
                                </div>
                                <div class="form-group-separator"></div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label" for="algorithmDscription">算法描述 <font color="red">*</font></label>
                                    <div class="col-sm-6">
                                        <textarea class="form-control autogrow" cols="5" name="algorithmDscription" id="algorithmDscription" maxlength="200" required></textarea>
                                    </div>
                                </div>
                                <div class="form-group-separator"></div>
                                <input type="text" class="form-control" name="id1" id="id1">
								<input type="text" class="form-control" name="fileID" id="fileID">
                                <div class="form-group col-sm-6 pull-right" >
                                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                    <button type="button" class="btn btn-primary" id="updateAlgorithm">修改</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--查看算法结束-->

<%-- 尾部内容 --%>
<jsp:include page="/WEB-INF/jsps/template_tail.jsp" />

<!-- Imported scripts on this page -->
<script src="assets/js/jquery-ui.min.js"></script>
</body>

</html>